//
//  IndexOtherView.m
//  YunFu
//
//  Created by Bager on 2018/8/31.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "IndexOtherView.h"

#import "IndexTwoItemSizeCell.h"
#import "IndexFourItemSizeCell.h"

@implementation IndexOtherView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = HexColor(0xf4f5f6);
    }
    return self;
}

- (void)setViews
{
    [self createView];
    [self createTitleView];
}

- (void)createTitleView
{
    UILabel *labelDown = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 45, 5, 90, 30)];
    labelDown.textAlignment = NSTextAlignmentCenter;
    labelDown.text = self.titleStr;
    labelDown.font = [UIFont systemFontOfSize:14];
    labelDown.backgroundColor = self.colorArray[0];
    labelDown.layer.cornerRadius = 14;
    labelDown.layer.masksToBounds = YES;
    labelDown.adjustsFontSizeToFitWidth = YES;
    labelDown.textColor = [UIColor whiteColor];
    [self addSubview:labelDown];
}

- (void)createView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置每个item的大小，
    //    flowLayout.itemSize = CGSizeMake((kScreenWidth - kPublicMargin * 2) / 2.0, 80);
    // 设置列的最小间距
    flowLayout.minimumInteritemSpacing = 0;
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 0;
    // 设置布局的内边距
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    // 滚动方向
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.otherCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(kPublicMargin, 20, kScreenWidth - kPublicMargin * 2, 160)  collectionViewLayout:flowLayout];
    
    self.otherCollectionView.backgroundColor = [UIColor whiteColor];
    
    self.otherCollectionView.dataSource = self;
    
    self.otherCollectionView.delegate = self;
    
    [self.otherCollectionView registerClass:[IndexTwoItemSizeCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
    [self.otherCollectionView registerClass:[IndexFourItemSizeCell class] forCellWithReuseIdentifier:@"cellIdentifiers"];
    
    
    self.otherCollectionView.layer.cornerRadius = 4;
    self.otherCollectionView.layer.masksToBounds = YES;
    
    [self addSubview:self.otherCollectionView];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.imgArray.count;
}

- (CGSize) collectionView:(UICollectionView *)collectionView
                   layout:(UICollectionViewLayout *)collectionViewLayout
   sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.item > 1)
    {
        return CGSizeMake((kScreenWidth - kPublicMargin * 2) / 4.0, 70);
    }
    else
    {
        return CGSizeMake((kScreenWidth - kPublicMargin * 2) / 2.0, 80);
    }
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.item > 1)
    {
        IndexFourItemSizeCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifiers" forIndexPath:indexPath];
        
        [cell.img setImage:[UIImage imageNamed:self.imgArray[indexPath.item]]];
        cell.name.text = self.nameArray[indexPath.item];
        
        return cell;
    }
    else
    {
        IndexTwoItemSizeCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
        
        [cell.img setImage:[UIImage imageNamed:self.imgArray[indexPath.item]]];
        cell.name.text = self.nameArray[indexPath.item];
        
        return cell;
    }
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

@end
